package com.jgp.security.controller;

import com.jgp.common.annotation.UIParam;
import com.jgp.security.secmodel.SecResource;
import com.jgp.security.service.SecResourceService;
import com.jgp.sys.annotation.PowerType;
import com.jgp.sys.controller.JGPBackController;
import com.jgp.sys.ui.GridResult;
import com.jgp.sys.ui.Pager;
import com.jgp.sys.ui.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2019-11-03
 */
@RestController
@RequestMapping("/security/resource-api-ctl")
public class ResourceApiController extends JGPBackController {
    
    @Autowired
    private SecResourceService service;
    
    @RequestMapping("scan-and-generate")
    public Result scanAndGenerate(){
        service.scanAndGenerate();
        return ajaxRe(true);
    }
    
    @RequestMapping("query")
    public Result query(String action, String remark, PowerType powerType, @UIParam("pager") Pager pager){
        List<SecResource> list = service.query(action, remark, powerType, pager);
        List<GridResult.Category> categories = new ArrayList<>();
        categories.add(new GridResult.Category("说明", "remark"));
        categories.add(new GridResult.Category("组", "groupRemark"));
        categories.add(new GridResult.Category("资源类型", "powerType"));
        //categories.add(new GridResult.Category("权限标识符", "action"));
        return ajaxReGrid("gdata", categories, list, pager);
    }
}
